Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change link template config type from an array to a record. Support link template functions #1008

Merged
merged 4 commits into from
Jun 20, 2024

Conversation

delatrie
Copy link
Collaborator

Context

The PR changes the link patterns configuration type from the array to the record whose keys are either LinkType values or arbitrary strings. A link's template can now be an arbitrary function from string to string. LinkConfig is now defined as follows:

export type LinkConfig<TOpts extends LinkTypeOptions = LinkTypeOptions> =
  Partial<Record<LinkType, TOpts>> & Record<string, TOpts>;
  1. A generic type argument is used to allow integrations to extend link options. Allure-cucumber does that to add an extra pattern field to the options.

  2. Defining the config as an intersection allows us to:

    • keep IDE autocompletion
    • index the values with arbitrary string keys (TS infers the resulting type to be TOpts instead of TOpts | undefined in such cases, but that's how it works for any record without the noUncheckedIndexedAccess TS option).

Some examples:

import type { Config } from "allure-js-commons/sdk/reporter";
import { LinkType } from "allure-js-commons";

const config: Config = {
  issue: { // Hinted by IDE autocompletion
    urlTemplate: "https://foo/%s"
  },
  [LinkType.DEFAULT]: { // Enum as the key
    urlTemplate: "https://bar/%s"
  },
  custom: { // An arbitrary string
    urlTemplate: "https://baz/%s",
    nameTemplate: "CUSTOM-%s",
  },
  tms: { // Template functions
    urlTemplate: (v) => `https://baz/${v}`,
    nameTemplate: (v) => `CUSTOM-${v}`,
  }
};

Checklist

@delatrie delatrie added the type:improvement Improvement or request label Jun 19, 2024
@github-actions github-actions bot added theme:api Javascript API related issue theme:jest Jest related issue theme:cucumberjs CucumberJS related issue theme:jasmine Jasmine related issue theme:playwright theme:codeceptjs theme:vitest labels Jun 19, 2024
@delatrie delatrie marked this pull request as ready for review June 19, 2024 10:37
@delatrie delatrie force-pushed the link-pattern-record branch from 139fc24 to 99e4a56 Compare June 20, 2024 11:36
@baev baev merged commit f1ef515 into main Jun 20, 2024
8 checks passed
@baev baev deleted the link-pattern-record branch June 20, 2024 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme:api Javascript API related issue theme:codeceptjs theme:cucumberjs CucumberJS related issue theme:jasmine Jasmine related issue theme:jest Jest related issue theme:playwright theme:vitest type:improvement Improvement or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants